package cn.xmy.demo01.servlet;

import cn.xmy.demo01.pojo.Address;
import cn.xmy.demo01.service.AddressService;
import cn.xmy.demo01.service.impl.AddressServiceImpl;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;


import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/updateFindAddressServlet")
public class UpdateFindAddressServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        AddressService addressService=new AddressServiceImpl();
        String id=request.getParameter("id");
        Address address=null;
        try {
            address=addressService.findAllAddressById(id);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
        request.setAttribute("address", address);
        request.getRequestDispatcher("updateAddress.html").forward(request, response);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}